package com.ysz.globalexception.assertutil;

import com.ysz.globalexception.components.BaseException;
import com.ysz.globalexception.components.BusinessException;

import java.util.Objects;

/**
 * @ClassName BusinessExceptionAssert
 * @Description 业务异常断言
 * @Data 13:38
 * @Version 1.0
 * @Author ysz
 */
public interface BusinessExceptionAssert extends BaseAssert, IResponse {

    @Override
    default Throwable createException(Throwable e, Integer code, String msg, Object data) {
        if (Objects.nonNull(e)) {
            return e;
        }
        return new BusinessException(e, code, msg, data);
    }

    @Override
    default void notNull(Object arg) throws Throwable {
        if (Objects.isNull(arg)) {
            throw this.createException(null, this.getCode(), this.getMsg(), this.getData());
        }
    }

    @Override
    default void notNull(Throwable e, Object arg) throws Throwable {
        if (Objects.isNull(arg)) {
            throw this.createException(e, this.getCode(), this.getMsg(), this.getData());
        }
    }
}
